package com.rsk.datasource.sharding.rules;

import io.shardingjdbc.core.api.config.TableRuleConfiguration;
import io.shardingjdbc.core.api.config.strategy.InlineShardingStrategyConfiguration;

public class SysUserRules1 {
	
	/**
	 * sys_users表分片策略
	 * @return
	 */
	public static TableRuleConfiguration sysUsersRulesConfig() {
		// 配置user表规则
	    TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
	    tableRuleConfig.setLogicTable("sys_users");
	    tableRuleConfig.setActualDataNodes("dba1.sys_users0,dba1.sys_users1");
	    tableRuleConfig.setKeyGeneratorColumnName("id");
	    // 配置分库 + 分表策略
	    //tableRuleConfig.setDatabaseShardingStrategyConfig(new InlineShardingStrategyConfiguration("id", "ds${id % 2}"));
	    tableRuleConfig.setTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("id", "sys_users${id % 2}"));
		return tableRuleConfig;
	}
}
